Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 1x 1x 1x 1x 1x | import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
type Params = {
params: Promise<{
id: string
}>
}
// GET /api/products/[id] - Get a single product
export async function GET(request: Request, { params }: Params) {
try {
const { id } = await params
const product = await prisma.product.findUnique({
where: { id },
include: {
reviews: {
where: { status: 'approved' },
orderBy: { createdAt: 'desc' },
},
},
})
Eif (!product) {
return NextResponse.json({ error: 'Product not found' }, { status: 404 })
}
return NextResponse.json(product)
} catch (error) {
console.error('Error fetching product:', error)
return NextResponse.json({ error: 'Failed to fetch product' }, { status: 500 })
}
}
|